package com.joysuch.wwyt.core.repository;

import com.joysuch.wwyt.core.entity.BaseImageTypeRepository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;


import java.util.List;


/**
 * @Author ZhaoQiuWei
 * @Date 2021/5/12 10:25
 */
public interface BaseImageTypeRepositoryDao extends JpaRepository<BaseImageTypeRepository, Long> {

    List<BaseImageTypeRepository> findByImageIdAndTypeCode(Long imageId, String typeCode);

    @Query(value = " select * from wwyt_base_image_type_repository where type_code in ?1 and delete_flag = '0'", nativeQuery = true)
    List<BaseImageTypeRepository> findByTypeCodes(List<String> typeCode);

    @Modifying
    @Query(value = "update wwyt_base_image_type_repository set delete_flag = '1' where id in ?1", nativeQuery = true)
    void deleteByIds(List<Long> ids);

    @Query(value = " select * from wwyt_base_image_type_repository where image_id =?1 and type_code in ?2 and delete_flag = '0' limit 1", nativeQuery = true)
    BaseImageTypeRepository findByImageIdAndTypeCodes(Long id, List<String> codes);

    @Query(value = " select * from wwyt_base_image_type_repository where image_id =?1 and type_code in('user_cap','staff_cap') and delete_flag = '0'", nativeQuery = true)
    List<BaseImageTypeRepository> findByHeadImage(Long id);

    @Query(value = "select * from wwyt_base_image_type_repository where type_code = 'logo' and delete_flag = '0' and tenent_id = ?1 and org_code like ?2% limit 1 ", nativeQuery = true)
    BaseImageTypeRepository findLogoType(Long tenentId, String orgCode);
}
